export default {
    namespaced: true,
    state: {

        // 登陆状态
        loginState: false,
        // token
        token: '',
        //用户信息 userInfo:{}
        userInfo: {}
    },
    getters: {

    },
    mutations: {
        user_login(state, user) {
            state.loginState = true;
            state.token = user.data.token;
            state.userInfo = user.data;
            //    数据永久化存储
            localStorage.setItem('teaUserInfo', JSON.stringify(user))
        },
        // 读取
        init_user(state) {
            let user = JSON.parse(localStorage.getItem('teaUserInfo'))
            if (user) {
                state.loginState = true;
                state.token = user.data.token;
                state.userInfo = user.data;
            }
        },
        // 退出登录
        loginOut(state){
            state.loginState = false;
            state.token = null;
            state.userInfo = {};
            localStorage.removeItem('teaUserInfo')  
        }
    },
    actions: {

    }
}